package com.excellence.controller;

import com.excellence.datamodel.Result;
import com.excellence.pojo.User;
import com.excellence.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName UserController
 * @Description TODO
 * @date 2024/4/8 11:40
 * @Version 1.0
 */
//@Controller
//@ResponseBody
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userService;

    @DeleteMapping("/deleteByKey")
    Result deleteByKey(Integer id) {
        int res = userService.deleteByKey(id);
        return Result.success(res);
    }

    @DeleteMapping("/deleteByPrimaryKey")
    Result deleteByPrimaryKey(Integer id) {
        int res = userService.deleteByPrimaryKey(id);
        return Result.success(res);
    }

    @PostMapping("/insert")
    Result insert(User record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        String message = userService.insert(record, files);
        return Result.success(200, message);
    }

    @PostMapping("/insertSelective")
    Result insertSelective(@RequestBody User record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = userService.insertSelective(record, files);
        return Result.success(res);
        //没测
    }

    @GetMapping("/selectByPrimaryKey")
    Result selectByPrimaryKey(Integer id) {
        User res = userService.selectByPrimaryKey(id);
        return Result.success(res);
    }

    @GetMapping("/selectAll")
    Result selectAll() {
        List<User> res = userService.selectAll();
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKeySelective")
    Result updateByPrimaryKeySelective(User record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = userService.updateByPrimaryKeySelective(record, files);
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKey")
    Result updateByPrimaryKey(User record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = userService.updateByPrimaryKey(record, files);
        return Result.success(res);
        //没测
    }
}
